package com.jhhc.Config;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;


@Configuration
@MapperScan(value = {"com.jhhc.StormSurgeForecast.StormSurge.Dao","com.jhhc.StormSurgeForecast.Calculate.Dao"}, sqlSessionFactoryRef = "sqlSessionFactory5")
public class StormSurgeConfig {
    /**
     * 和总配置文件注入bean名称一致 其他无需修改
     */
    @Autowired
    @Qualifier("stormsurgeDataSource")
    private DataSource ds5;

    @Bean(name = "sqlSessionFactory5")
    @Primary
    public SqlSessionFactory sqlSessionFactory5() throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(ds5);
        return sqlSessionFactoryBean.getObject();
    }

    @Bean
    @Primary
    public SqlSessionTemplate sqlSessionTemplate5() throws Exception {
        return new SqlSessionTemplate(sqlSessionFactory5());
    }

}
